package com.erp.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.erp.dto.Reply;
import com.erp.dto.Topic;

@SuppressWarnings("serial")
@Entity
@Table(name = "t_topic")
public class TTopic extends TArticle implements java.io.Serializable {

	private String title; // 标题
	private Integer replyCount = 0;// 回复数量，需手动维护,默认0
	private Integer maxFloor = 0;// 最大楼层，需手动维护
	private TReply lasttReply;// 最后回复
	private Date lastUpdateTime;// 最后更新时间（主题发表时间或最后回复的时间）
	private TForum tForum;// 所属版块
	private List<TReply> tReplies = new ArrayList<TReply>();// 所有回复

	public TTopic() {
	}

	public TTopic(Topic topic) {
		super(topic);
		this.title = topic.getTitle();
		this.replyCount = topic.getReplyCount();
		this.maxFloor = topic.getMaxFloor();
		this.lastUpdateTime = topic.getLastUpdateTime();
		Reply lastReply = topic.getLastReply();
		if (lastReply != null) {
			this.lasttReply = new TReply(lastReply);
		}
		this.tForum = new TForum(topic.getForum());
	}

	@Column(name = "title")
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name = "replyCount")
	public Integer getReplyCount() {
		return replyCount;
	}

	public void setReplyCount(Integer replyCount) {
		this.replyCount = replyCount;
	}

	@Column(name = "maxFloor")
	public Integer getMaxFloor() {
		return maxFloor;
	}

	public void setMaxFloor(Integer maxFloor) {
		this.maxFloor = maxFloor;
	}

	/**
	 * 本类与TReply是一对一单向关系
	 * 
	 * @return
	 */
	@OneToOne
	@JoinColumn(name = "lastReply_id")
	public TReply getLasttReply() {
		return lasttReply;
	}

	public void setLasttReply(TReply lasttReply) {
		this.lasttReply = lasttReply;
	}

	@Column(name = "lastUpdateTime")
	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	/**
	 * 本类与TForum的多对一双向关系，tForum为映射属性
	 * 
	 * @return
	 */
	@ManyToOne
	@JoinColumn(name = "forum_id")
	public TForum gettForum() {
		return tForum;
	}

	public void settForum(TForum tForum) {
		this.tForum = tForum;
	}

	/**
	 * 本类与TReply是一对多双向关系，tTopic为映射属性
	 */
	@OneToMany(mappedBy = "tTopic")
	public List<TReply> gettReplies() {
		return tReplies;
	}

	public void settReplies(List<TReply> tReplies) {
		this.tReplies = tReplies;
	}
}
